package cn.devices.service.impl;

import cn.devices.dto.InventoryDto;
import cn.devices.entity.TbInventory;
import cn.devices.mapper.TbInventoryMapper;
import cn.devices.service.TbInventoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 盘点清单 服务实现类
 * </p>
 *
 * @author 秋水浮萍
 * @since 2021-02-07
 */
@Service
public class TbInventoryServiceImpl implements TbInventoryService {

    @Autowired
    private TbInventoryMapper tbInventoryMapper;

    @Override
    public int tbInventoryAdd(TbInventory tbInventory) {
        return tbInventoryMapper.tbInventoryAdd(tbInventory);
    }

    @Override
    public String status(String deviceCode) {
        return tbInventoryMapper.status(deviceCode);
    }

    @Override
    public PageInfo<TbInventory> testInventoryList(int pageIndex, int pageSize, String taskId) {
        PageHelper.startPage(pageIndex, pageSize);
        List<TbInventory> tbInventoryList = tbInventoryMapper.testInventoryList(taskId);
        return new PageInfo<>(tbInventoryList);
    }


    @Override
    public TbInventory tbInventoryById(String taskId, String deviceCode) {
        return tbInventoryMapper.tbInventoryById(taskId, deviceCode);
    }

    @Override
    public int tbInventoryAdds(List<String> devices, String taskId) {
        return tbInventoryMapper.tbInventoryAdds(devices, taskId);
    }

    @Override
    public PageInfo<InventoryDto> inventoryDt(int pageIndex, int pageSize, String taskId) {
        PageHelper.startPage(pageIndex, pageSize);
        List<InventoryDto> tbInventoryList = tbInventoryMapper.inventoryDt(taskId);
        for (InventoryDto dto:tbInventoryList
             ) {
            if ("1".equals(dto.getDeviceStatus())) dto.setDeviceStatus("设备正常");
           else if ("2".equals(dto.getDeviceStatus())) dto.setDeviceStatus("设备故障");
        }
        return new PageInfo<>(tbInventoryList);
    }
}
